<?php

namespace Yj\Generator\Core\Dao;

use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
use Yj\Generator\Core\Dao\Processor\ClassNameProcessor;
use Yj\Generator\Core\Dao\Processor\MethodProcessor;
use Yj\Generator\Core\Dao\Processor\NamespaceProcessor;
use Yj\Generator\Core\Dao\Template\BaseTemplate;
use Yj\Generator\Core\Model\EloquentModel;

class Generator
{
    protected $processors = null;

    protected $tags = [
        ClassNameProcessor::class,
        NamespaceProcessor::class,
        MethodProcessor::class,
    ];
    
    private function register()
    {
        return new RewindableGenerator(function () {
            foreach ($this->tags as $abstract) {
                yield make($abstract);
            }
        }, count($this->tags));
    }

    public function __construct()
    {
        if (is_null($this->processors)) {
            $this->processors = $this->register();
        }

    }

    /**
     * @Notes:【】
     * @User: zwc
     * @Date: 2022/3/2 19:44
     * @return BaseTemplate
     */
    public function create(Config $config)
    {
        $template = new BaseTemplate();
        foreach ($this->processors as $processor) {
            $processor->process($template, $config);
        }
        return $template;
    }
}